﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

namespace AnalyseServer
{
    public class NumericUtils
    {
        public static float ReadSingleBigEndian(BinaryReader binReader)
        {
            return ReadSingle(binReader, false);
        }
        public static float ReadSingleLittleEndian(BinaryReader binReader)
        {
            return ReadSingle(binReader, true);
        }
        
        private static float ReadSingle(BinaryReader binReader, bool littleEndian)
        {
            byte[] data = binReader.ReadBytes(4);
            if (BitConverter.IsLittleEndian != littleEndian)
            {   // other-endian; reverse this portion of the data (4 bytes)

                byte tmp = data[0];
                data[0] = data[3];
                data[3] = tmp;

                tmp = data[1];
                data[1] = data[2];
                data[2] = tmp;
            }
            return BitConverter.ToSingle(data, 0);
        }
    }
}
